package com.example.shengyin.frontController;


import com.example.shengyin.entity.City;
import com.example.shengyin.service.CityService;
import com.example.shengyin.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * AdminController
 *
 * @author ruoyi
 * @date 2023-07-29
 */
@RestController
@RequestMapping("front/city")
@Validated
//@CrossOrigin(origins = "*", maxAge = 3600,allowCredentials="true")
//swagger
@Api(tags = "FrontCityController", description = "城市")
public class FrontCityController
{
    @Autowired
    private CityService service;


    @ApiOperation("传id 0显示全部省，传省的id得到市")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable(value = "id") Long id){
        List<City> allProvince = service.selectById(id);
        if (allProvince==null|allProvince.size()==0)
            return Result.error(null);
        return Result.success(allProvince);
    }


    @ApiOperation("单个查找城市")
    @GetMapping(value = "/select/{id}")
    public Result select(@PathVariable(value = "id") Long id)
    {
        City select = service.select(id);
        if(select==null)
            return Result.error("没有找到数据");
        return Result.success(select);
    }
    @ApiOperation("传当前name获得当前id")
    @GetMapping("/selectIdByName/{name}")
    public Result selectIdByName(@PathVariable(value = "name") String name){
        Long aLong = service.selectIdByName(name);
        return Result.success(aLong);
    }


    @ApiOperation("传parentid查上级的name")
    @GetMapping("/selectIdByName/{parentid}")
    public Result selectNameByParentid(@PathVariable(value = "parentid")Long parentid){
        String parentidname = service.selectNameByParentid(parentid);
        return Result.success(parentidname);
    }


}
